﻿using System;
using System.Collections;

namespace YArchitech.HCLoad.XmlData
{
	public class ChildCollect : Hashtable
	{
		public ChildCollect(RoomLoad roomLoad)
		{
			this.parent = roomLoad;
		}

		public RoomLoad Parent
		{
			get
			{
				return this.parent;
			}
			set
			{
				this.parent = value;
			}
		}

		public DataBase DataBase
		{
			get
			{
				return this.Parent.Room.DataBase;
			}
		}

		public int AddChildWhJg(ChildWhJg childWhJg)
		{
			int result;
			try
			{
				childWhJg.ParentChildCollect = this;
				int num = this.DataBase.AddCurrID();
				childWhJg.ID = num;
				this.Add(num, childWhJg);
				this.DataBase.hCurrIDList.Add(num, childWhJg);
				result = num;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public void RemoveChildWhJg(int ID)
		{
			try
			{
				this.Remove(ID);
				this.DataBase.hCurrIDList.Remove(ID);
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public ChildWhJg GetChildWhJg(int ID)
		{
			ChildWhJg result;
			try
			{
				result = (ChildWhJg)this[ID];
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public bool LoadChildWhJg(ChildWhJg childWhJg)
		{
			bool result;
			try
			{
				childWhJg.ParentChildCollect = this;
				int id = childWhJg.ID;
				if (this.DataBase.hCurrIDList.ContainsKey(id))
				{
					result = false;
				}
				else
				{
					if (id > this.DataBase.CurrID)
					{
						this.DataBase.CurrID = id;
					}
					this.Add(id, childWhJg);
					this.DataBase.hCurrIDList.Add(id, childWhJg);
					result = true;
				}
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		private RoomLoad parent;
	}
}
